package com.chart.web.controller.chart;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chart.chart.domian.ChartConfigs;
import com.chart.chart.domian.ChartLegendData;
import com.chart.chart.domian.vo.ChartSmartVo;
import com.chart.chart.domian.vo.ChartXData;
import com.chart.chart.domian.vo.ChartXDataVo;
import com.chart.chart.service.IChartConfigsService;
import com.chart.chart.service.IChartConfigsUserService;
import com.chart.common.core.controller.BaseController;
import com.chart.common.core.domain.AjaxResult;
import com.chart.common.utils.ExcelDataUtils;
import com.chart.common.utils.ExcelUtils;
import com.chart.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.chart.web.controller.chart.sta.LineChartController.setCellValue;

/**
 * 智能图表
 *
 * @author chart
 */
@RestController
@RequestMapping("/smart/chart")
public class ChartSmartController extends BaseController {


    @Autowired
    private IChartConfigsService chartConfigsService;

    @Autowired
    private IChartConfigsUserService chartConfigsUserService;


    private static Map<Integer, String> dataTemplate = new HashMap<>();

    static {
        //多组
        dataTemplate.put(1, "/static/template/分组数据模板.xlsx");
        //单组
        dataTemplate.put(2, "/static/template/无分组数据模板.xlsx");
        //热力图（最大最小值）
        dataTemplate.put(3, "/static/template/热力图数据模板.xlsx");
        //盒须图
        dataTemplate.put(4, "/static/template/盒须数据模板.xlsx");
//        双列数据
        dataTemplate.put(5, "/static/template/数值数据模板.xlsx");
        //饼图
        dataTemplate.put(6, "/static/template/饼图数据模板.xlsx");
        //基础柱状图
        dataTemplate.put(7, "/static/template/基础柱状图数据模板.xlsx");
    }

    /*    *//**
     * 根据configId解析excel模版数据返回Lint<List<String>>类型
     *
     * @param configId
     * @return
     *//*
    @PostMapping("/analyses/excel")
    public AjaxResult selectByconfig(@RequestParam(required = false) Integer configId) {
        System.out.println(configId);
        try {
            // 根据 configId 查询 ChartConfigs 对象
            ChartConfigs configs = chartConfigsService.getById(configId);
            if (configs == null) {
                return AjaxResult.error("配置对象不存在");
            }

            // 构造完整的 excelurl
            String templateUrl = configs.getTemplateUrl();
            String serverUrl = "https://www.topcharts.cn";
            String excelurl = serverUrl + templateUrl;
            System.out.println(excelurl);
            // 使用 Apache POI 读取 Excel 文件内容
            Workbook workbook = null;
            InputStream inputStream = null;
            try {
                URL url = new URL(excelurl);
                inputStream = url.openStream();
                workbook = new XSSFWorkbook(inputStream); // 使用 XSSFWorkbook 对象打开输入流
                // 假设只有一个工作表
                Sheet sheet = workbook.getSheetAt(0);
                // 读取 Excel 数据，从第9行开始读取
                List<List<String>> data = readExcelData(sheet, 8); // 从第9行开始读取数据

                // 返回 AjaxResult 封装的数据
                return AjaxResult.success(data);
            } finally {
                if (workbook != null) {
                    workbook.close(); // 关闭工作簿
                }
                if (inputStream != null) {
                    inputStream.close(); // 关闭输入流
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            String errorMsg = (e.getMessage() != null) ? e.getMessage() : "null";
            return AjaxResult.error("读取 Excel 文件出现异常：" + errorMsg);
        }
    }*/

    @PostMapping("/analyses/excel")
    public AjaxResult selectByconfig(@RequestParam(required = false) Integer configId) {
        System.out.println(configId);
        try {
            // 根据 configId 查询 ChartConfigs 对象
            ChartConfigs configs = chartConfigsService.getById(configId);
            if (configs == null) {
                return AjaxResult.error("配置对象不存在");
            }

            // 构造完整的 excelurl
            String templateUrl = configs.getTemplateUrl();
            String serverUrl = "https://www.topcharts.cn";
            String excelurl = serverUrl + templateUrl;
            System.out.println(excelurl);

            // 使用 Apache POI 读取 Excel 文件内容
            Workbook workbook = null;
            InputStream inputStream = null;
            try {
                URL url = new URL(excelurl);
                inputStream = url.openStream();
                workbook = new XSSFWorkbook(inputStream); // 使用 XSSFWorkbook 对象打开输入流
                // 假设只有一个工作表
                Sheet sheet = workbook.getSheetAt(0);
                // 读取 Excel 数据，从第9行开始读取
                List<Map<String, String>> data = readExcelData(sheet, 8); // 从第9行开始读取数据

                // 返回 AjaxResult 封装的数据
                return AjaxResult.success(data);
            } finally {
                if (workbook != null) {
                    workbook.close(); // 关闭工作簿
                }
                if (inputStream != null) {
                    inputStream.close(); // 关闭输入流
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            String errorMsg = (e.getMessage() != null) ? e.getMessage() : "null";
            return AjaxResult.error("读取 Excel 文件出现异常：" + errorMsg);
        }
    }
    private List<Map<String, String>> readExcelData(Sheet sheet, int startRow) {
        List<Map<String, String>> data = new ArrayList<>();
        try {
            // 遍历行
            for (int i = startRow; i <= sheet.getLastRowNum(); i++) {
                Row row = sheet.getRow(i);
                if (row == null) {
                    continue; // 如果行为空，跳过
                }

                Map<String, String> rowData = new LinkedHashMap<>();
                // 遍历单元格
                for (int j = 0; j < row.getLastCellNum(); j++) {
                    Cell cell = row.getCell(j);
                    String cellValue = "";
                    if (cell != null) {
                        CellType cellType = cell.getCellType();
                        if (cellType == CellType.STRING) {
                            cellValue = cell.getStringCellValue();
                        } else if (cellType == CellType.NUMERIC) {
                            cellValue = String.valueOf(cell.getNumericCellValue());
                        }
                    }
                    rowData.put("column" + (j + 1), cellValue);
                }
                // 将一行数据添加到整体数据列表中
                data.add(rowData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }


   // @PostMapping("/importData1")
    public AjaxResult importData1(MultipartFile file, Long configId) throws Exception {
        XSSFWorkbook workbook = null;
        try {
            workbook = new XSSFWorkbook(file.getInputStream());
            Sheet sheet = workbook.getSheetAt(1);

            List<List<String>> data = ExcelDataUtils.getData(sheet);
            if (CollectionUtils.isEmpty(data)) {
                return AjaxResult.error("请填充数据");
            }
            //获取
            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 1).orderByAsc(ChartConfigs::getId));

//            List<List<String>> data = ExcelDataUtils.getData(sheet);

            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart = null;
                if (i == 0) {
                    //堆叠柱状图、带包络线的分组堆叠柱状图、
                    chart = getChartV1(ExcelDataUtils.getData(sheet), id);
                }
//                else if (i == 1) {
//                    //三维散点图
                chart = getChartV2(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
//                }
                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }
            }
            return AjaxResult.success(newList);
        } finally {
            workbook.close();
        }
    }


    /**
     * 导入分组堆叠柱状图数据1
     *
     * @param dataList
     * @param configId
     * @param dataList
     * @param configId
     * @return
     * @reGturn
     */
    @ApiOperation("导入分组堆叠柱状图数据1")
    @PostMapping("v2/importData1")
    public AjaxResult vimportData1(@RequestBody List<Map<String, Object>> dataList, Long configId) {
        try {
            if (CollectionUtils.isEmpty(dataList)) {
                return AjaxResult.error("请填充数据");
            }

            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>()
                    .eq(ChartConfigs::getDataType, 1).orderByAsc(ChartConfigs::getId));

            List<List<String>> data = wrapListMapToList(dataList);

            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart = null;
                if (i == 0) {
                    // 堆叠柱状图、带包络线的分组堆叠柱状图
                    chart = getChartV1(data, id);
                }

                //转换json
                JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                chart.setConfigValueJson(jsonObject);
                //end

                if (i == 1) {
                    // 三维散点图
                    chart = getChartV2(data, configsList.get(i).getId());
                }

                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }

            }
            return AjaxResult.success(newList);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("处理数据时出现异常");
        }
    }


    private List<List<String>> wrapListMapToList(List<Map<String, Object>> dataList) {
        List<List<String>> data = new ArrayList<>();//  [["1","4"],[33,666]]
        for (Map<String, Object> row : dataList) {
            List<String> rowData = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                rowData.add(entry.getValue().toString());
            }
            data.add(rowData);
        }
        return data;
    }





    public Sheet convertDataListToSheet(List<Map<String, Object>> dataList) {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("DataSheet");

        if (dataList == null || dataList.isEmpty()) {
            return sheet; // 返回一个空的Sheet
        }
        // 创建标题行
        Row headerRow = sheet.createRow(0);
        Map<String, Object> firstRow = dataList.get(0);
        int cellIndex = 0;
        for (String key : firstRow.keySet()) {
            Cell cell = headerRow.createCell(cellIndex++);
            cell.setCellValue(key);
        }

        // 填充数据行
        int rowIndex = 1;
        for (Map<String, Object> dataMap : dataList) {
            Row row = sheet.createRow(rowIndex++);
            cellIndex = 0;
            for (String key : firstRow.keySet()) {
                Cell cell = row.createCell(cellIndex++);
                Object value = dataMap.get(key);
                if (value != null) {
                    cell.setCellValue(value.toString());
                } else {
                    cell.setCellValue("");
                }
            }
        }

        return sheet;
    }



    /**
     * 导入彩色像素热力图数据3
     *
     * @param dataList
     * @param configId
     * @return
     * @throws Exception
     */
    @ApiOperation("导入彩色像素热力图数据3")
    @PostMapping("v2/importData3")
    public AjaxResult v2importData3(@RequestBody List<Map<String, Object>> dataList, Long configId) throws Exception {

        if (CollectionUtils.isEmpty(dataList)) {
            return AjaxResult.error("请填充数据");
        }

        Sheet sheet = ExcelUtils.convertDataListToSheetRemoveNineAndOne(dataList);


        // 转换 dataList 中的数据结构，从 Map 转为 List<List<String>>
        List<List<String>> data = new ArrayList<>();
        for (Map<String, Object> row : dataList) {
            List<String> rowData = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                rowData.add(entry.getValue().toString());
            }
            data.add(rowData);
        }


        // 获取最小值和最大值的验证
        // 获取最小值和最大值的验证
        // 获取最小值和最大值的验证
        if (data.size() > 0 && data.get(0).size() > 1 && ObjectUtils.isEmpty(data.get(0).get(1))) {
            return AjaxResult.error("请输入最小值");
        }
        if (data.size() > 1 && data.get(1).size() > 1 && ObjectUtils.isEmpty(data.get(1).get(1))) {
            return AjaxResult.error("请输入最大值");
        }

        ArrayList<ChartSmartVo> newList = new ArrayList<>();
        List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 3).orderByAsc(ChartConfigs::getId));

        for (int i = 0; i < configsList.size(); i++) {
            Long id = configsList.get(i).getId();
            ChartSmartVo chart = null;

            if (i == 0) {
                // 彩色像素热力图
                chart = getChartV31(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            } else if (i == 1) {
                // 3D折线图
                chart = getChartV32(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            } else if (i == 2) {
                // 对角线相关矩阵
                chart = getChartV33(data, configsList.get(i).getId());
            } else if (i == 3) {
                // 具有不同点大小和色调的散点图
                chart = getChartV34(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            } else if (i == 4) {
                // 关节和边缘直方图
                chart = getChartV35(ExcelDataUtils.getData(sheet), configsList.get(i).getId(), sheet);
            } else if (i == 5) {
                // 热力图 - 大数据量
                chart = getChartV36(ExcelDataUtils.getData(sheet), configsList.get(i).getId(), sheet);
            }
            //start
            // 解析 configValue 字段为 JSON 对象并设置到 chart 中
            if (chart != null && chart.getConfigValue() != null) {
                JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                chart.setConfigValueJson(jsonObject);
            }
            //end
            if (configId.equals(id)) {
                newList.add(0, chart);
            } else {
                newList.add(chart);
            }
        }
        return AjaxResult.success(newList);

    }


    /**
     * 导入盒须图数据4
     *
     * @param dataList
     * @param configId
     * @return
     */
    @ApiOperation("导入盒须图数据4")
    @PostMapping("v2/importData4")
    public AjaxResult v2importData4(@RequestBody List<Map<String, Object>> dataList, Long configId) {

        if (CollectionUtils.isEmpty(dataList)) {
            return AjaxResult.error("请填充数据");
        }

        // 转换 dataList 中的数据结构，从 Map 转为 List<List<String>>
        List<List<String>> data = new ArrayList<>();
        for (Map<String, Object> row : dataList) {
            List<String> rowData = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                if (entry.getValue() != null) {
                    rowData.add(entry.getValue().toString());
                } else {
                    rowData.add(""); // 处理空值情况，避免空指针异常
                }
            }
            data.add(rowData);
        }

        ArrayList<ChartSmartVo> newList = new ArrayList<>();
        List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>()
                .eq(ChartConfigs::getDataType, 4).orderByAsc(ChartConfigs::getId));

        // 遍历 configsList，处理每个图表配置
        for (ChartConfigs config : configsList) {
            Long id = config.getId();
            ChartSmartVo chart = getChartV41(data, id);

            if (chart != null && chart.getConfigValue() != null) {
                JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                chart.setConfigValueJson(jsonObject);
            }
            // 确保 getChartV41 方法返回非空对象
            if (chart != null) {
                // 添加新的 chart 到 newList 中
                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }
            }
        }

        return AjaxResult.success(newList);
    }




    @ApiOperation("导入散点图数据5")
    @PostMapping("v2/importData5")
    public AjaxResult v2importData5(@RequestBody List<Map<String, Object>> dataLists
            , Long configId) throws Exception {
        //  XSSFWorkbook workbook = null;
        try {
            //   workbook = new XSSFWorkbook(file.getInputStream());
            // Sheet sheet = workbook.getSheetAt(1);

            Sheet sheet = ExcelUtils.convertDataListToSheetRemoveNineAndOne(dataLists);

            List<List<String>> rowData = ExcelDataUtils.getData(sheet);
            if (CollectionUtils.isEmpty(rowData)) {
                return AjaxResult.error("请填充数据");
            }
            //获取
            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 5).orderByAsc(ChartConfigs::getId));
            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart = null;
                List<List<String>> list = new ArrayList<>();
                if (i == 0) {
                    //散点图
//                    list.addAll(colData);
                    chart = getChartV51(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
                } else if (i == 1) {
                    //多元线性回归图
//                    list.addAll(colData);
                    chart = getChartV52(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
                } else if (i == 2) {
                    //极坐标图
//                    list.addAll(colData);
                    chart = getChartV53(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
                }
                //start
                // 解析 configValue 字段为 JSON 对象并设置到 chart 中
                if (chart != null && chart.getConfigValue() != null) {
                    JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                    chart.setConfigValueJson(jsonObject);
                }
                //end
                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }
            }
            return AjaxResult.success(newList);
        } finally {
            // workbook.close();
        }
    }

  /*  @ApiOperation("导入散点图数据5")
    @PostMapping("v2/importData5")
    public AjaxResult vimportData5(@RequestBody List<Map<String, Object>> dataList, Long configId) throws Exception {

        // 将 dataList 转换为 Sheet 对象
        Sheet sheet = convertDataListToSheet(dataList);
        List<List<String>> rowData = new ArrayList<>();
        for (Map<String, Object> row : dataList) {
            List<String> rowDataList = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                rowDataList.add(entry.getValue().toString());
            }
            rowData.add(rowDataList);
        }

        //获取
        ArrayList<ChartSmartVo> newList = new ArrayList<>();
        List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 5).orderByAsc(ChartConfigs::getId));

        for (int i = 0; i < configsList.size(); i++) {
            Long id = configsList.get(i).getId();
            ChartSmartVo chart = null;
            List<List<String>> list = new ArrayList<>();
            if (i == 0) {
                //散点图
//                    list.addAll(colData);
                chart = getChartV51(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            } else if (i == 1) {
                //多元线性回归图
//                    list.addAll(colData);
                chart = getChartV52(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            } else if (i == 2) {
                //极坐标图
//                    list.addAll(colData);
                chart = getChartV53(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
            }
            //start
            // 解析 configValue 字段为 JSON 对象并设置到 chart 中
            if (chart != null && chart.getConfigValue() != null) {
                JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                chart.setConfigValueJson(jsonObject);
            }
            //end
            if (configId.equals(id)) {
                newList.add(0, chart);
            } else {
                newList.add(chart);
            }
        }
        return AjaxResult.success(newList);

    }*/


  //  @PostMapping("/importData6")
    public AjaxResult importData6(MultipartFile file, Long configId) throws Exception {
        XSSFWorkbook workbook = null;
        try {
            workbook = new XSSFWorkbook(file.getInputStream());
            Sheet sheet = workbook.getSheetAt(1);

            List<List<String>> getdata = ExcelDataUtils.getData(sheet);
            if (CollectionUtils.isEmpty(getdata)) {
                return AjaxResult.error("请填充数据");
            }
            //获取
            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 6).orderByAsc(ChartConfigs::getId));

            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart = null;
                if (i == 0 || i == 1 || i == 3) {
                    //南丁格尔图、扇形图，圆角环形图
                    chart = getChartV62(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
                } else if (i == 2) {
                    //漏斗图
                    chart = getChartV63(ExcelDataUtils.getData(sheet), configsList.get(i).getId());
                }

                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }
            }
            return AjaxResult.success(newList);
        } finally {
            workbook.close();
        }
    }


    @ApiOperation("导入南丁格尔图数据6")
    @PostMapping("/v2/importData6")
    @Transactional(rollbackFor = Exception.class) // 添加事务管理注解，捕获所有异常回滚事务
    public AjaxResult v2importData6(@RequestBody List<Map<String, Object>> dataList, Long configId) throws Exception {
        // XSSFWorkbook workbook = null;
        try {
            if (CollectionUtils.isEmpty(dataList)) {
                return AjaxResult.error("请填充数据");
            }

            // 从 dataList 中获取 Excel 数据
            List<List<String>> getdata = extractDataFromList(dataList);
            if (CollectionUtils.isEmpty(getdata)) {
                return AjaxResult.error("请填充数据");
            }

            // 获取图表数据
            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>()
                    .eq(ChartConfigs::getDataType, 6).orderByAsc(ChartConfigs::getId));

            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart = null;

                if (i == 0 || i == 1 || i == 3) {
                    // 南丁格尔图、扇形图、圆角环形图
                    chart = getChartV62(getdata, configsList.get(i).getId());
                } else if (i == 2) {
                    // 漏斗图
                    chart = getChartV63(getdata, configsList.get(i).getId());
                }

                if (chart != null && chart.getConfigValue() != null) {
                    JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                    chart.setConfigValueJson(jsonObject);
                }

                if (chart != null && chart.getConfigValue() != null) {
                    JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
                    chart.setConfigValueJson(jsonObject);
                }

                if (chart == null) {
                    // 如果获取图表失败或为空，记录日志或处理逻辑
                    logger.error("获取图表失败或图表为空，configId={}, id={}", configId, id);
                    // 返回相应的错误信息或处理逻辑
                    return AjaxResult.error("获取图表失败或为空");
                }

                if (configId.equals(id)) {
                    newList.add(0, chart);
                } else {
                    newList.add(chart);
                }
            }

            return AjaxResult.success(newList);
        } finally {
            {
                //    workbook.close();
            }
        }
    }

    @PostMapping("v2/importData7")
    public AjaxResult VimportData7(@RequestBody List<Map<String, Object>> dataLists, Long configId) throws Exception {
//*      workbook = new XSSFWorkbook(file.getInputStream());
//        Sheet sheet = workbook.getSheetAt(1);*//*

        //;
        // Sheet sheet = ExcelUtils.convertDataListToSheets(dataLists);
        List<List<String>> datas = ExcelUtils.wrapListMapToList(dataLists);

        Sheet sheet = ExcelUtils.convertDataListToSheetRemoveNineAndOne(dataLists);
        List<List<String>> data = ExcelDataUtils.getColData(sheet);
        if (CollectionUtils.isEmpty(data)) {
            return AjaxResult.error("请填充数据");
        }

        //获取
        ArrayList<ChartSmartVo> newList = new ArrayList<>();
        List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 7).orderByAsc(ChartConfigs::getId));

//            List<List<String>> data = ExcelDataUtils.getData(sheet);

        for (int i = 0; i < configsList.size(); i++) {
            Long id = configsList.get(i).getId();


            ChartSmartVo chart = null;
            //基础柱状图，基础折线图
            chart = getChartV71(ExcelDataUtils.getColData(sheet), id);

            //转换json
            JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
            chart.setConfigValueJson(jsonObject);
            //end

            if (configId.equals(id)) {
                newList.add(0, chart);
            } else {
                newList.add(chart);
            }
        }

        return AjaxResult.success(newList);

    }



/*// 将 dataList 转换为 Sheet 对象
        // Sheet sheet = convertDataListToSheet(dataList);
        List<List<String>> data = new ArrayList<>();//  [["1","4"],[33,666]]
        for (Map<String, Object> row : dataList) {
            List<String> rowData = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                rowData.add(entry.getValue().toString());
            }
            data.add(rowData);
        }

        //获取
        ArrayList<ChartSmartVo> newList = new ArrayList<>();
        List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 7).orderByAsc(ChartConfigs::getId));

        for (int i = 0; i < configsList.size(); i++) {
            Long id = configsList.get(i).getId();
            ChartSmartVo chart = null;
            //基础柱状图，基础折线图
            //  chart = getChartV71(ExcelDataUtils.getColData(sheet), id);
            chart = getChartV71(data, id);
            //转换json
            JSONObject jsonObject = JSONObject.parseObject(chart.getConfigValue());
            chart.setConfigValueJson(jsonObject);
            //end
            if (configId.equals(id)) {
                newList.add(0, chart);
            } else {
                newList.add(chart);
            }
        }
        return AjaxResult.success(newList);*/


   // @PostMapping("/importData7")
    public AjaxResult importData7(MultipartFile file,Long configId) throws Exception {
        XSSFWorkbook workbook = null;
        try {
            workbook = new XSSFWorkbook(file.getInputStream());
            Sheet sheet = workbook.getSheetAt(1);

            List<List<String>> data = ExcelDataUtils.getColData(sheet);
            if (CollectionUtils.isEmpty(data)) {
                return AjaxResult.error("请填充数据");
            }
            //获取
            ArrayList<ChartSmartVo> newList = new ArrayList<>();
            List<ChartConfigs> configsList = chartConfigsService.list(new LambdaQueryWrapper<ChartConfigs>().eq(ChartConfigs::getDataType, 7).orderByAsc(ChartConfigs::getId));

//            List<List<String>> data = ExcelDataUtils.getData(sheet);

            for (int i = 0; i < configsList.size(); i++) {
                Long id = configsList.get(i).getId();
                ChartSmartVo chart =null;
                //基础柱状图，基础折线图
                chart = getChartV71(ExcelDataUtils.getColData(sheet), id);
                if (configId.equals(id)) {
                    newList.add(0,chart);
                }else {
                    newList.add(chart);
                }
            }
            return AjaxResult.success(newList);
        }finally {
            workbook.close();
        }
    }

    private ChartSmartVo getChartV71(List<List<String>> getdata, Long configId) {
        List<Map> roomName = new ArrayList<>();

        List<String> strings = getdata.get(1);
        HashMap<String, String> map = new HashMap<>();
        map.put("name", strings.get(0));
        roomName.add(map);

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        legend.put("data",roomName);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");

        ArrayList<JSONObject> list = new ArrayList<>();
        for (int i = 0; i < series.size(); i++) {
            JSONObject o1 = series.get(i);
            o1.put("name",roomName.get(i).get("name"));
            List<String> list1 =getdata.get(i+1);
            ArrayList<String> newList = new ArrayList<>();
            for (int i1 = 1; i1 < list1.size(); i1++) {
                String s = list1.get(i1);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                    newList.add(s);
                }
            }
            o1.put("data",newList);
            list.add(o1);
        }

        JSONObject xAxis = (JSONObject) jsonObject.get("xAxis");
        List<String> strings1 = getdata.get(0);
        strings1.remove(0);

        xAxis.put("data",strings1);

        jsonObject.put("xAxis",xAxis);
        jsonObject.put("legend",legend);
        jsonObject.put("series",list);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    /**
     * 从 dataList 中提取 Excel 数据
     */
    private List<List<String>> extractDataFromList(List<Map<String, Object>> dataList) {
        List<List<String>> extractedData = new ArrayList<>();
        for (Map<String, Object> row : dataList) {
            List<String> rowData = new ArrayList<>();
            for (Map.Entry<String, Object> entry : row.entrySet()) {
                rowData.add(entry.getValue().toString());
            }
            extractedData.add(rowData);
        }
        return extractedData;
    }


    @GetMapping("/importTemplate")
    public String importTemplate(HttpServletResponse response, Integer dataType) throws IOException {
        return dataTemplate.get(dataType);
    }


    private ChartSmartVo getChartV64(List<List<String>> getdata, Long configId) {

        List<String> groupName = new ArrayList<>();

        List<List<List<String>>> newList = new ArrayList<>();

        List<List<String>> list = new ArrayList<>();


        for (int i = 1; i < getdata.size(); i++) {
            if (i == getdata.size() - 1) {
                List<String> sdata = getdata.get(i);
                list.add(sdata);
                newList.add(list);
            } else if (i == 1) {
                List<String> gName = getdata.get(i);
                groupName.add(gName.get(0));
            } else {
                if (getdata.get(i).size() == 1) {
                    List<String> gName = getdata.get(i);
                    groupName.add(gName.get(0));
                    newList.add(list);
                    list = new ArrayList<>();
                } else {
                    List<String> sdata = getdata.get(i);
                    list.add(sdata);
                }
            }
        }

        ArrayList<Map> maps = new ArrayList<>();

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject json = series.get(0);

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();


        for (int i = 0; i < newList.size(); i++) {
            List<List<String>> lists = newList.get(i);
            HashMap<String, Object> map = new HashMap<>();
            map.put("source", lists);
            maps.add(map);

            double[] x = new double[lists.size()];
            double[] y = new double[lists.size()];

            for (int i1 = 0; i1 < lists.size(); i1++) {
                List<String> sources = lists.get(i1);
                for (int i2 = 0; i2 < sources.size(); i2++) {
                    x[i1] = Double.parseDouble(sources.get(0));
                    y[i1] = Double.parseDouble(sources.get(1));
                }
            }
            Map service = ExcelDataUtils.getService1(x, y);
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.putAll(json);
            jsonObject1.put("datasetIndex", i);
            jsonObject1.put("name", groupName.get(i));
            JSONObject markLine1 = (JSONObject) jsonObject1.get("markLine");
            JSONObject markLine = new JSONObject();
            markLine.putAll(markLine1);
            JSONObject label1 = (JSONObject) markLine.get("label");
            JSONObject label = new JSONObject();
            label.putAll(label1);
            label.put("formatter", service.get("formatter"));
            markLine.put("label", label);

            JSONObject tooltip1 = (JSONObject) markLine.get("tooltip");
            JSONObject tooltip = new JSONObject();
            tooltip.putAll(tooltip1);
            tooltip.put("formatter", service.get("formatter"));
            markLine.put("tooltip", tooltip);

            List<JSONObject> data = (List<JSONObject>) markLine.get("data");
            List<JSONObject> data1 = (List<JSONObject>) data.get(0);
            List<JSONObject> jsonObjects1 = new ArrayList<>();
            List<List<JSONObject>> jsonObjects2 = new ArrayList<>();
            for (int i1 = 0; i1 < data1.size(); i1++) {
                JSONObject jsonObject2 = data1.get(i1);
                JSONObject jsonObject3 = new JSONObject();
                jsonObject3.putAll(jsonObject2);
                if (i1 == 0) {
                    jsonObject3.put("coord", service.get("min"));
                } else {
                    jsonObject3.put("coord", service.get("max"));
                }
                jsonObjects1.add(jsonObject3);
            }
            jsonObjects2.add(jsonObjects1);
            markLine.put("data", jsonObjects2);
            jsonObject1.put("markLine", markLine);
            jsonObjects.add(jsonObject1);
        }


        jsonObject.put("series", jsonObjects);
        jsonObject.put("dataset", maps);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV63(List<List<String>> getdata, Long configId) {


        List<JSONObject> list = new ArrayList<>();

        List<String> name = new ArrayList<>();

        for (int i = 2; i < getdata.size(); i++) {
            List<String> strings = getdata.get(i);
            JSONObject jsonObject = new JSONObject();
            for (int i1 = 0; i1 < strings.size(); i1++) {
                String s = strings.get(i1);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                    if (i1 == 0) {
                        jsonObject.put("name", s);
                        name.add(s);
                    } else if (i1 == 1) {
                        jsonObject.put("value", Double.parseDouble(s));
                    }
                }
            }
            list.add(jsonObject);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());


        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        for (int i = 0; i < series.size(); i++) {
            JSONObject jsonObject1 = series.get(i);
            jsonObject1.put("data", list);
        }

        JSONObject legend = (JSONObject) jsonObject.get("legend");

        legend.put("data", name);
        jsonObject.put("legend", legend);
        jsonObject.put("series", series);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV62(List<List<String>> getdata, Long configId) {

        List<List<Object>> newList = new ArrayList<>();


        for (int i = 1; i < getdata.size(); i++) {
            List<String> strings = getdata.get(i);
            if (!CollectionUtils.isEmpty(strings)) {
                List<Object> list = new ArrayList<>();
                for (int i1 = 0; i1 < strings.size(); i1++) {
                    String s = strings.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        if (i == 1) {
                            list.add("name");
                            list.add("value");
                        } else {
                            if (i1 == 0) {
                                list.add(s);
                            } else {
                                list.add(Double.parseDouble(s));
                            }
                        }
                    }
                }
                newList.add(list);
            }
        }

        List<Map> maps = new ArrayList<>();

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());


        HashMap<String, Object> map = new HashMap<>();
        map.put("source", newList);
        maps.add(map);
        jsonObject.put("dataset", maps);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

//    private ChartSmartVo getChartV61(List<List<String>> getdata, Long configId) {
//        List<String> groupName = new ArrayList<>();
//
//        List<List<List<String>>> newList = new ArrayList<>();
//
//        List<List<String>> list = new ArrayList<>();
//
//
//        for (int i = 1; i < getdata.size(); i++) {
//            if (i == getdata.size() - 1) {
//                List<String> sdata = getdata.get(i);
//                list.add(sdata);
//                newList.add(list);
//            } else if (i == 1) {
//                List<String> gName = getdata.get(i);
//                groupName.add(gName.get(0));
//            } else {
//                if (getdata.get(i).size() == 1) {
//                    List<String> gName = getdata.get(i);
//                    groupName.add(gName.get(0));
//                    newList.add(list);
//                    list = new ArrayList<>();
//                } else {
//                    List<String> sdata = getdata.get(i);
//                    list.add(sdata);
//                }
//            }
//        }
//
//
//        ChartConfigs configs = chartConfigsService.getById(configId);
//        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
//        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
//
//        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
//        List<List<String>> lists = newList.get(0);
//
//        for (int i = 0; i < series.size(); i++) {
//            JSONObject jsonObject1 = series.get(i);
//
//            if (i == 0) {
//                lists = newList.get(i);
//                jsonObject1.put("data", lists);
//            } else {
//                double[] x = new double[lists.size()];
//                double[] y = new double[lists.size()];
//                for (int i1 = 0; i1 < lists.size(); i1++) {
//                    List<String> sources = lists.get(i1);
//                    for (int i2 = 0; i2 < sources.size(); i2++) {
//                        x[i1] = Double.parseDouble(sources.get(0));
//                        y[i1] = Double.parseDouble(sources.get(1));
//                    }
//                }
//                List<List<String>> service = ExcelDataUtils.getService2(x, y);
//
//                jsonObject1.put("data", service);
//            }
//            jsonObjects.add(jsonObject1);
//        }
//
//
//        jsonObject.put("series", jsonObjects);
//
//        ChartSmartVo chartSmartVo = new ChartSmartVo();
//        chartSmartVo.setConfigId(configs.getId());
//        chartSmartVo.setConfigName(configs.getConfigName());
//        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
//        chartSmartVo.setChartTypeId(configs.getChartTypeId());
//        return chartSmartVo;
//    }

//    private ChartSmartVo getChartV52(List<List<String>> getdata, Long configId) {
//
//        List<String> groupName = new ArrayList<>();
//
//        List<List<List<String>>> newList = new ArrayList<>();
//
//        List<List<String>> list = new ArrayList<>();
//
//
//        for (int i = 1; i < getdata.size(); i++) {
//            if (i==getdata.size()-1) {
//                List<String> sdata = getdata.get(i);
//                list.add(sdata);
//                newList.add(list);
//            }else if(i==1){
//                List<String> gName = getdata.get(i);
//                groupName.add(gName.get(0));
//            }else {
//                if (getdata.get(i).size()==1) {
//                    List<String> gName = getdata.get(i);
//                    groupName.add(gName.get(0));
//                    newList.add(list);
//                    list = new ArrayList<>();
//                }else {
//                    List<String> sdata = getdata.get(i);
//                    list.add(sdata);
//                }
//            }
//        }
//
//        ArrayList<Map> maps = new ArrayList<>();
//
//        ChartConfigs configs = chartConfigsService.getById(configId);
//        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
//
//
//
//        for (int i = 0; i < newList.size(); i++) {
//            List<List<String>> lists = newList.get(i);
//            HashMap<String, Object> map = new HashMap<>();
//            map.put("source", lists);
//            maps.add(map);
//        }
//
//        List<JSONObject> jsonObjects = new ArrayList<>();
//        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
//        JSONObject jsonObject1 = series.get(0);
//        for (int i = 0; i < groupName.size(); i++) {
//            JSONObject jsonObject2 = new JSONObject();
//            jsonObject2.putAll(jsonObject1);
//            jsonObject2.put("name",groupName.get(i));
//            jsonObject2.put("xAxisIndex",i);
//            jsonObject2.put("yAxisIndex",i);
//            jsonObject2.put("datasetIndex",i);
//
//            jsonObjects.add(jsonObject2);
//        }
//
//        jsonObject.put("dataset",maps);
//        jsonObject.put("series",jsonObjects);
//
//        ChartSmartVo chartSmartVo = new ChartSmartVo();
//        chartSmartVo.setConfigId(configs.getId());
//        chartSmartVo.setConfigName(configs.getConfigName());
//        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
//        chartSmartVo.setChartTypeId(configs.getChartTypeId());
//        return chartSmartVo;
//    }

//    private ChartSmartVo getChartV51(List<List<String>> getdata, Long configId) {
//        List<String> groupName = new ArrayList<>();
//
//        List<List<List<String>>> newList = new ArrayList<>();
//
//        List<List<String>> list = new ArrayList<>();
//
//
//        for (int i = 1; i < getdata.size(); i++) {
//            if (i==getdata.size()-1) {
//                List<String> sdata = getdata.get(i);
//                list.add(sdata);
//                newList.add(list);
//            }else if(i==1){
//                List<String> gName = getdata.get(i);
//                groupName.add(gName.get(0));
//            }else {
//                if (getdata.get(i).size()==1) {
//                    List<String> gName = getdata.get(i);
//                    groupName.add(gName.get(0));
//                    newList.add(list);
//                    list = new ArrayList<>();
//                }else {
//                    List<String> sdata = getdata.get(i);
//                    list.add(sdata);
//                }
//            }
//        }
//
//        ArrayList<Map> maps = new ArrayList<>();
//
//        ChartConfigs configs = chartConfigsService.getById(configId);
//        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
//        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
//        JSONObject json = series.get(0);
//
//        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
//
//
//        for (int i = 0; i < newList.size(); i++) {
//            List<List<String>> lists = newList.get(i);
//            HashMap<String, Object> map = new HashMap<>();
//            map.put("source",lists);
//            maps.add(map);
//
//            double[] x = new double[lists.size()];
//            double[] y = new double[lists.size()];
//
//            for (int i1 = 0; i1 < lists.size(); i1++) {
//                List<String> sources = lists.get(i1);
//                for (int i2 = 0; i2 < sources.size(); i2++) {
//                    x[i1]=Double.parseDouble(sources.get(0));
//                    y[i1]=Double.parseDouble(sources.get(1));
//                }
//            }
//            Map service = ExcelDataUtils.getService1(x, y);
//            JSONObject jsonObject1 = new JSONObject();
//            jsonObject1.putAll(json);
//            jsonObject1.put("datasetIndex",i);
//            jsonObject1.put("name",groupName.get(i));
//            JSONObject markLine1 = (JSONObject) jsonObject1.get("markLine");
//            JSONObject markLine = new JSONObject();
//            markLine.putAll(markLine1);
//            JSONObject label1 = (JSONObject) markLine.get("label");
//            JSONObject label = new JSONObject();
//            label.putAll(label1);
//            label.put("formatter",service.get("formatter"));
//            markLine.put("label",label);
//
//            JSONObject tooltip1 = (JSONObject) markLine.get("tooltip");
//            JSONObject tooltip = new JSONObject();
//            tooltip.putAll(tooltip1);
//            tooltip.put("formatter",service.get("formatter"));
//            markLine.put("tooltip",tooltip);
//
//            List<JSONObject> data = (List<JSONObject>) markLine.get("data");
//            List<JSONObject> data1 = (List<JSONObject>) data.get(0);
//            List<JSONObject> jsonObjects1 = new ArrayList<>();
//            List<List<JSONObject>> jsonObjects2 = new ArrayList<>();
//            for (int i1 = 0; i1 < data1.size(); i1++) {
//                JSONObject jsonObject2 = data1.get(i1);
//                JSONObject jsonObject3 = new JSONObject();
//                jsonObject3.putAll(jsonObject2);
//                if (i1==0) {
//                    jsonObject3.put("coord",service.get("min"));
//                }else {
//                    jsonObject3.put("coord",service.get("max"));
//                }
//                jsonObjects1.add(jsonObject3);
//            }
//            jsonObjects2.add(jsonObjects1);
//            markLine.put("data",jsonObjects2);
//            jsonObject1.put("markLine",markLine);
//            jsonObjects.add(jsonObject1);
//        }
//
//
//        jsonObject.put("series",jsonObjects);
//        jsonObject.put("dataset",maps);
//        ChartSmartVo chartSmartVo = new ChartSmartVo();
//        chartSmartVo.setConfigId(configs.getId());
//        chartSmartVo.setConfigName(configs.getConfigName());
//        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
//        chartSmartVo.setChartTypeId(configs.getChartTypeId());
//        return chartSmartVo;
//    }

    private ChartSmartVo getChartV41(List<List<String>> getdata, Long configId) {
        List<String> groupName = new ArrayList<>();

        List<List<Object>> gruopDatas = new ArrayList<>();


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        List<JSONObject> dataset = (List<JSONObject>) jsonObject.get("dataset");

        List<JSONObject> datasetList = new ArrayList<>();


        for (int i = 1; i < getdata.size(); i++) {
            List<Object> gruopData = new ArrayList<>();
            List<String> colData = new ArrayList<>();
            List<String> data = getdata.get(i);
            for (int i1 = 0; i1 < data.size(); i1++) {
                String s = data.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    colData.add(s);
                }
            }

            if (!CollectionUtils.isEmpty(colData)) {
                if (i == getdata.size() - 1) {
                    JSONObject jsonObject1 = new JSONObject();
                    for (int i1 = 0; i1 < colData.size(); i1++) {
                        gruopData.add(Double.parseDouble(colData.get(i1)));
                    }
                    gruopDatas.add(gruopData);
                    jsonObject1.put("source", gruopDatas);
                    datasetList.add(jsonObject1);
                } else if (i == 1) {
                    groupName.add(colData.get(0));
                } else {
                    if (colData.size() == 1) {
                        groupName.add(colData.get(0));
                        JSONObject jsonObject1 = new JSONObject();
                        jsonObject1.put("source", gruopDatas);
                        datasetList.add(jsonObject1);
                        gruopDatas = new ArrayList<>();
                    } else {
                        for (int i1 = 0; i1 < colData.size(); i1++) {
                            gruopData.add(Double.parseDouble(colData.get(i1)));
                        }
                        gruopDatas.add(gruopData);
                    }
                }
            }
        }

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        ArrayList<JSONObject> seriesList = new ArrayList<>();
        JSONObject jsonObject1 = series.get(0);

        JSONObject jsonObject2 = dataset.get(dataset.size() - 1);
        for (int i = 0; i < groupName.size(); i++) {
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.putAll(jsonObject2);
            jsonObject3.put("fromDatasetIndex", i);
            datasetList.add(jsonObject3);

            JSONObject jsonObject4 = new JSONObject();
            jsonObject4.putAll(jsonObject1);
            jsonObject4.put("name", groupName.get(i));
            jsonObject4.put("datasetIndex", i + groupName.size());
            seriesList.add(jsonObject4);
        }
        jsonObject.put("dataset", datasetList);

        jsonObject.put("series", seriesList);

        JSONObject legend = (JSONObject) jsonObject.get("legend");

        ArrayList<Map> maps = new ArrayList<>();
        for (int i = 0; i < groupName.size(); i++) {
            Map map = new HashMap<>();
            map.put("name", groupName.get(i));
            maps.add(map);
        }

        legend.put("data", maps);
        jsonObject.put("legend", legend);


        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV36(List<List<String>> getdata, Long configId, Sheet sheet) {
        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);
        getdata.remove(0);
        getdata.remove(0);


        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (!ObjectUtils.isEmpty(getdata.get(i)) && !getdata.get(i).equals("")) {
                if (i == 0) {
                    List<String> list = getdata.get(i);
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        if (!ObjectUtils.isEmpty(list.get(i1)) && !list.get(i).equals("")) {
                            xList.add(list.get(i1));
                        }
                    }
                } else {
                    String y = getdata.get(i).get(0);
                    if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                        yList.add(y);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }

        List<List<Object>> newDataList = new ArrayList<>();
        xList.remove(0);
        for (int i = 0; i < xList.size(); i++) {
            String x = xList.get(i);
            for (int j = 0; j < yList.size(); j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String y = yList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }

            }
        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        String minMaxAxis = JSON.toJSONString(jsonObject.get("visualMap"));
        JSONObject jsonObjectMinMAx = JSON.parseObject(minMaxAxis);
        jsonObjectMinMAx.put("min", Double.parseDouble(minV));
        jsonObjectMinMAx.put("max", Double.parseDouble(maxV));
        jsonObject.put("visualMap", jsonObjectMinMAx);


        String dataAxis = JSON.toJSONString(jsonObject.get("series"));
        JSONObject jsonObjectData = JSON.parseObject(dataAxis);
        jsonObjectData.put("data", newDataList);
        jsonObject.put("series", jsonObjectData);


        String xAxis = JSON.toJSONString(jsonObject.get("xAxis"));
        JSONObject jsonObjectX = JSON.parseObject(xAxis);
        jsonObjectX.put("data", xList);
        jsonObject.put("xAxis", jsonObjectX);

        String yAxis = JSON.toJSONString(jsonObject.get("yAxis"));
        JSONObject jsonObjectY = JSON.parseObject(yAxis);
        jsonObjectY.put("data", yList);
        jsonObject.put("yAxis", jsonObjectY);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV35(List<List<String>> getdata, Long configId, Sheet sheet) {

        List<Double> colDataSum = ExcelDataUtils.getColDataSum(sheet);
        List<Double> rowDataSum = ExcelDataUtils.getRowDataSum(sheet);

        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);
        getdata.remove(0);
        getdata.remove(0);


        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (!ObjectUtils.isEmpty(getdata.get(i)) && !getdata.get(i).equals("")) {
                if (i == 0) {
                    List<String> list = getdata.get(i);
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        if (!ObjectUtils.isEmpty(list.get(i1)) && !list.get(i).equals("")) {
                            xList.add(list.get(i1));
                        }
                    }
                } else {
                    String y = getdata.get(i).get(0);
                    if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                        yList.add(y);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }

        List<List<Object>> newDataList = new ArrayList<>();
        xList.remove(0);
        for (int i = 0; i < xList.size(); i++) {
            String x = xList.get(i);
            for (int j = 0; j < yList.size(); j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String y = yList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }

            }
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        List<JSONObject> xAxis = (List<JSONObject>) jsonObject.get("xAxis");
        for (int i = 0; i < xAxis.size(); i++) {
            if (i == 0 || i == 1) {
                JSONObject jsonObject1 = xAxis.get(i);
                jsonObject1.put("data", xList);
            }
        }


        List<JSONObject> yAxis = (List<JSONObject>) jsonObject.get("yAxis");
        for (int i = 0; i < yAxis.size(); i++) {
            if (i == 0 || i == 2) {
                JSONObject jsonObject1 = yAxis.get(i);
                jsonObject1.put("data", yList);
            }
        }

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        for (int i = 0; i < series.size(); i++) {
            if (i == 0) {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", newDataList);
            } else if (i == 1) {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", colDataSum);
            } else {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", rowDataSum);
            }
        }

        String minMaxAxis = JSON.toJSONString(jsonObject.get("visualMap"));
        JSONObject jsonObjectMinMAx = JSON.parseObject(minMaxAxis);
        jsonObjectMinMAx.put("min", Double.parseDouble(minV));
        jsonObjectMinMAx.put("max", Double.parseDouble(maxV));


        jsonObject.put("visualMap", jsonObjectMinMAx);
        jsonObject.put("xAxis", xAxis);
        jsonObject.put("yAxis", yAxis);
        jsonObject.put("series", series);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

  /*  private ChartSmartVo getChartV35(List<List<String>> getdata, Long configId, Sheet sheet) {

        List<Double> colDataSum = ExcelDataUtils.getColDataSum(getdata);
        List<Double> rowDataSum = ExcelDataUtils.getRowDataSum(getdata);

        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);
        getdata.remove(0);
        getdata.remove(0);


        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (!ObjectUtils.isEmpty(getdata.get(i)) && !getdata.get(i).equals("")) {
                if (i == 0) {
                    List<String> list = getdata.get(i);
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        if (!ObjectUtils.isEmpty(list.get(i1)) && !list.get(i).equals("")) {
                            xList.add(list.get(i1));
                        }
                    }
                } else {
                    String y = getdata.get(i).get(0);
                    if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                        yList.add(y);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }

        List<List<Object>> newDataList = new ArrayList<>();
        xList.remove(0);
        for (int i = 0; i < xList.size(); i++) {
            String x = xList.get(i);
            for (int j = 0; j < yList.size(); j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String y = yList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }

            }
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        List<JSONObject> xAxis = (List<JSONObject>) jsonObject.get("xAxis");
        for (int i = 0; i < xAxis.size(); i++) {
            if (i == 0 || i == 1) {
                JSONObject jsonObject1 = xAxis.get(i);
                jsonObject1.put("data", xList);
            }
        }


        List<JSONObject> yAxis = (List<JSONObject>) jsonObject.get("yAxis");
        for (int i = 0; i < yAxis.size(); i++) {
            if (i == 0 || i == 2) {
                JSONObject jsonObject1 = yAxis.get(i);
                jsonObject1.put("data", yList);
            }
        }

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        for (int i = 0; i < series.size(); i++) {
            if (i == 0) {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", newDataList);
            } else if (i == 1) {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", colDataSum);
            } else {
                JSONObject jsonObject1 = series.get(i);
                jsonObject1.put("data", rowDataSum);
            }
        }

        String minMaxAxis = JSON.toJSONString(jsonObject.get("visualMap"));
        JSONObject jsonObjectMinMAx = JSON.parseObject(minMaxAxis);
        jsonObjectMinMAx.put("min", Double.parseDouble(minV));
        jsonObjectMinMAx.put("max", Double.parseDouble(maxV));


        jsonObject.put("visualMap", jsonObjectMinMAx);
        jsonObject.put("xAxis", xAxis);
        jsonObject.put("yAxis", yAxis);
        jsonObject.put("series", series);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;


    }*/


    private ChartSmartVo getChartV34(List<List<String>> getdata, Long configId) {
        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);

        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 2; i < getdata.size(); i++) {
            List<String> list = getdata.get(i);
            if (!CollectionUtils.isEmpty(list)) {
                List<String> newList = new ArrayList<>();
                for (int i1 = 0; i1 < list.size(); i1++) {
                    String s = list.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        newList.add(s);
                    }
                }
                if (!CollectionUtils.isEmpty(newList)) {
                    if (i == 2) {
                        newList.remove(0);
                        xList.addAll(newList);
                    } else {
                        String y = newList.get(0);
                        yList.add(y);
                        newList.remove(0);
                        dataList.add(newList);
                    }
                }
            }
        }


        List<List<Object>> newDataList = new ArrayList<>();
        List<Object> biao = new ArrayList<>();
        biao.add("x");
        biao.add("y");
        biao.add("z");
        newDataList.add(biao);
        for (int i = 0; i < yList.size(); i++) {
            String y = yList.get(i);
            for (int j = 0; j < xList.size(); j++) {
                String s = dataList.get(i).get(j);
                String x = xList.get(j);
                List<Object> cellList = new ArrayList<>();
                cellList.add(x);
                cellList.add(y);
                cellList.add(Double.parseDouble(s));
                newDataList.add(cellList);
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("source", newDataList);

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        List<JSONObject> visualMap = (List<JSONObject>) jsonObject.get("visualMap");
        for (int i = 0; i < visualMap.size(); i++) {
            JSONObject jsonObject1 = visualMap.get(i);
            jsonObject1.put("min", Double.parseDouble(minV));
            jsonObject1.put("max", Double.parseDouble(maxV));
        }
        jsonObject.put("visualMap", visualMap);

        jsonObject.put("dataset", map);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV33(List<List<String>> getdata, Long configId) {

        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);
        getdata.remove(0);
        getdata.remove(0);


        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (!ObjectUtils.isEmpty(getdata.get(i)) && !getdata.get(i).equals("")) {
                if (i == 0) {
                    List<String> list = getdata.get(i);
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        if (!ObjectUtils.isEmpty(list.get(i1)) && !list.get(i).equals("")) {
                            xList.add(list.get(i1));
                        }
                    }
                } else {
                    String y = getdata.get(i).get(0);
                    if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                        yList.add(y);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }

        List<List<Object>> newDataList = new ArrayList<>();
        xList.remove(0);
        for (int i = 0; i < xList.size(); i++) {
            String x = xList.get(i);
            for (int j = 0; j < yList.size() - i; j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String y = yList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }
            }
        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        String minMaxAxis = JSON.toJSONString(jsonObject.get("visualMap"));
        JSONObject jsonObjectMinMAx = JSON.parseObject(minMaxAxis);
        jsonObjectMinMAx.put("min", Double.parseDouble(minV));
        jsonObjectMinMAx.put("max", Double.parseDouble(maxV));
        jsonObject.put("visualMap", jsonObjectMinMAx);


        String dataAxis = JSON.toJSONString(jsonObject.get("series"));
        JSONObject jsonObjectData = JSON.parseObject(dataAxis);
        jsonObjectData.put("data", newDataList);
        jsonObject.put("series", jsonObjectData);


        String xAxis = JSON.toJSONString(jsonObject.get("xAxis"));
        JSONObject jsonObjectX = JSON.parseObject(xAxis);
        jsonObjectX.put("data", xList);
        jsonObject.put("xAxis", jsonObjectX);

        String yAxis = JSON.toJSONString(jsonObject.get("yAxis"));
        JSONObject jsonObjectY = JSON.parseObject(yAxis);
        jsonObjectY.put("data", yList);
        jsonObject.put("yAxis", jsonObjectY);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV32(List<List<String>> getdata, Long configId) {
        List<String> minList = getdata.get(0);
        List<String> maxList = getdata.get(1);

        String minV = minList.get(1);
        String maxV = maxList.get(1);

        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();


        List<List<String>> dataList = new ArrayList<>();
        for (int i = 2; i < getdata.size(); i++) {
            List<String> list = getdata.get(i);
            if (!CollectionUtils.isEmpty(list)) {
                List<String> newList = new ArrayList<>();
                for (int i1 = 0; i1 < list.size(); i1++) {
                    String s = list.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        newList.add(s);
                    }
                }
                if (!CollectionUtils.isEmpty(newList)) {
                    if (i == 2) {
                        newList.remove(0);
                        yList.addAll(newList);
                    } else {
                        String x = newList.get(0);
                        if (!ObjectUtils.isEmpty(x) && !x.equals("")) {
                            xList.add(x);
                        }
                        newList.remove(0);
                        dataList.add(newList);
                    }
                }
            }
        }


        List<List<Object>> newDataList = new ArrayList<>();
        for (int i = 0; i < yList.size(); i++) {
            String y = yList.get(i);
            for (int j = 0; j < xList.size(); j++) {
                String x = xList.get(j);
                List<Object> cellList = new ArrayList<>();
                cellList.add(x);
                cellList.add(y);
                cellList.add(Double.parseDouble(dataList.get(j).get(i)));
                newDataList.add(cellList);
            }
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(0);
        jsonObject1.put("data", newDataList);
        series.remove(0);
        series.add(jsonObject1);
        jsonObject.put("series", series);

        JSONObject minMaxAxis = (JSONObject) jsonObject.get("visualMap");
        minMaxAxis.put("min", Double.parseDouble(minV));
        minMaxAxis.put("max", Double.parseDouble(maxV));
        jsonObject.put("visualMap", minMaxAxis);

        JSONObject grid3D = (JSONObject) jsonObject.get("grid3D");
        if (xList.size() > 10 || yList.size() > 10) {
            grid3D.put("boxWidth", xList.size() * 8);
            grid3D.put("boxDepth", yList.size() * 4);

        } else if (xList.size() <= 10 && yList.size() <= 10) {
            grid3D.put("boxWidth", xList.size() * 20);
            grid3D.put("boxDepth", yList.size() * 10);
        }
        jsonObject.put("grid3D", grid3D);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV31(List<List<String>> getdata, Long configId) {

        String minV = getdata.get(0).get(1);
        String maxV = getdata.get(1).get(1);
        getdata.remove(0);
        getdata.remove(0);


        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();
        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (!ObjectUtils.isEmpty(getdata.get(i)) && !getdata.get(i).equals("")) {
                if (i == 0) {
                    List<String> list = getdata.get(i);
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        if (!ObjectUtils.isEmpty(list.get(i1)) && !list.get(i).equals("")) {
                            xList.add(list.get(i1));
                        }
                    }
                } else {
                    String y = getdata.get(i).get(0);
                    if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                        yList.add(y);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }

        List<List<Object>> newDataList = new ArrayList<>();
        xList.remove(0);
        for (int i = 0; i < xList.size(); i++) {
            String x = xList.get(i);
            for (int j = 0; j < yList.size(); j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String y = yList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }
            }
        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        String minMaxAxis = JSON.toJSONString(jsonObject.get("visualMap"));
        JSONObject jsonObjectMinMAx = JSON.parseObject(minMaxAxis);
        jsonObjectMinMAx.put("min", Double.parseDouble(minV));
        jsonObjectMinMAx.put("max", Double.parseDouble(maxV));
        jsonObject.put("visualMap", jsonObjectMinMAx);


        String dataAxis = JSON.toJSONString(jsonObject.get("series"));
        JSONObject jsonObjectData = JSON.parseObject(dataAxis);
        jsonObjectData.put("data", newDataList);
        jsonObject.put("series", jsonObjectData);


        String xAxis = JSON.toJSONString(jsonObject.get("xAxis"));
        JSONObject jsonObjectX = JSON.parseObject(xAxis);
        jsonObjectX.put("data", xList);
        jsonObject.put("xAxis", jsonObjectX);

        String yAxis = JSON.toJSONString(jsonObject.get("yAxis"));
        JSONObject jsonObjectY = JSON.parseObject(yAxis);
        jsonObjectY.put("data", yList);
        jsonObject.put("yAxis", jsonObjectY);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV30(List<List<String>> getdata, Long configId) {
        List<String> axleName = getdata.get(0);

        List<List<String>> dataList = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> rowData = getdata.get(i);
            if (!ObjectUtils.isEmpty(rowData)) {
                List<String> singleData = new ArrayList<>();
                for (int i1 = 1; i1 < rowData.size(); i1++) {
                    singleData.add(rowData.get(i1));
                }
                dataList.add(singleData);
            }
        }
        dataList.add(0, axleName);
        ChartXData xData = new ChartXData();
        xData.setSource(dataList);


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        for (int i = 1; i < series.size(); i++) {
            JSONObject jsonObject1 = series.get(i);
            if (i == 1) {
                JSONObject encode = (JSONObject) jsonObject1.get("encode");
                encode.put("x", axleName.get(0));
                encode.put("y", axleName.get(1));
            } else if (i == 2) {
                JSONObject encode = (JSONObject) jsonObject1.get("encode");
                encode.put("x", axleName.get(3));
                encode.put("y", axleName.get(0));
            } else if (i == 3) {
                JSONObject encode = (JSONObject) jsonObject1.get("encode");
                encode.put("x", axleName.get(0));
                encode.put("y", axleName.get(2));
            } else if (i == 4) {
                JSONObject encode = (JSONObject) jsonObject1.get("encode");
                encode.put("x", axleName.get(1));
                encode.put("y", axleName.get(2));
            }


        }
        jsonObject.put("series", series);
        jsonObject.put("dataset", xData);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV2(List<List<String>> getdata, Long configId) {
        List<String> axleName = new ArrayList<>();
        List<String> sss = getdata.get(0);
        for (int i = 1; i < sss.size(); i++) {
            String s = sss.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                axleName.add(s);
            }
        }

        List<List<List<String>>> newList = new ArrayList<>();

        List<List<String>> list = new ArrayList<>();

        List<String> groupName = new ArrayList<>();

        for (int i = 1; i < getdata.size(); i++) {
            List<String> rowData = getdata.get(i);
            if (!CollectionUtils.isEmpty(rowData)) {
                List<String> singleData = new ArrayList<>();
                for (int i1 = 0; i1 < rowData.size(); i1++) {
                    String s = rowData.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        singleData.add(s);
                    }
                }

                if (i == getdata.size() - 1) {
                    list.add(singleData);
                    newList.add(list);
                } else if (i == 1) {
                    groupName.add(singleData.get(0));
                } else {
                    if (getdata.get(i).size() == 1) {
                        groupName.add(singleData.get(0));
                        newList.add(list);
                        list = new ArrayList<>();
                    } else {
                        list.add(singleData);
                    }
                }
            }
        }


        ArrayList<Map> maps = new ArrayList<>();
        for (int i = 0; i < newList.size(); i++) {
            Map map = new HashMap<>();
            List<List<String>> lists = newList.get(i);

            List<List<String>> datas = new ArrayList<>();
            ArrayList<String> strings = new ArrayList<>();
            strings.add("x" + String.valueOf(i));
            strings.add("y" + String.valueOf(i));
            strings.add("z" + String.valueOf(i));
            datas.add(strings);
            for (int i1 = 0; i1 < lists.size(); i1++) {
                List<String> list1 = lists.get(i1);
                String y = list1.get(0);
                for (int i2 = 1; i2 < list1.size(); i2++) {
                    String x = axleName.get(i2 - 1);
                    List<String> ss = new ArrayList<>();
                    ss.add(x);
                    ss.add(y);
                    ss.add(list1.get(i2));
                    datas.add(ss);
                }
            }
            map.put("source", datas);
            maps.add(map);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        jsonObject.put("dataset", maps);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(0);

        ArrayList<JSONObject> seriesList = new ArrayList<>();
        ArrayList<Map> maps1 = new ArrayList<>();
        for (int i = 0; i < groupName.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);


            JSONObject encode = (JSONObject) jsonObject2.get("encode");
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.putAll(encode);
            jsonObject3.put("x", "x" + String.valueOf(i));
            jsonObject3.put("y", "y" + String.valueOf(i));
            jsonObject3.put("z", "z" + String.valueOf(i));

            jsonObject2.put("encode", jsonObject3);
            jsonObject2.put("name", groupName.get(i));
            seriesList.add(jsonObject2);

            Map map = new HashMap<>();
            map.put("name", groupName.get(i));
            maps1.add(map);
        }

        jsonObject.put("series", seriesList);
        JSONObject legend = (JSONObject) jsonObject.get("legend");
        legend.put("data", maps1);

        jsonObject.put("legend", legend);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV264(List<List<String>> getdata, Long configId) {
        List<String> xdata = new ArrayList<>();
        List<String> xlist = getdata.get(0);
        for (int i = 1; i < xlist.size(); i++) {
            String s = xlist.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                xdata.add(s);
            }
        }
//        xdata.remove(0);

        List<ChartXDataVo> chartXDataVos = new ArrayList<>();
        List<String> ydata = new ArrayList<>();
        List<List<Object>> groupList = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> list = getdata.get(i);

            List<Object> cellData = new ArrayList<>();
            for (int i1 = 0; i1 < list.size(); i1++) {
                String s = list.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    if (i1 == 0) {
                        ydata.add(s);
                    } else {
                        cellData.add(Double.parseDouble(s));
                    }
                }
            }
            groupList.add(cellData);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", chartXDataVos);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(1);

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        for (int i = 0; i < ydata.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);
            jsonObject2.put("data", groupList.get(i));
            jsonObject2.put("name", ydata.get(i));
            jsonObjects.add(jsonObject2);
        }
        jsonObject.put("series", jsonObjects);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
//            xdata.remove(0);
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 0; i < ydata.size(); i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(ydata.get(i));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);

        JSONObject xAxis = (JSONObject) jsonObject.get("xAxis");
        xAxis.put("data", xdata);
        jsonObject.put("xAxis", xAxis);


        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV263(List<List<String>> getdata, Long configId) {
        List<String> xlist = new ArrayList<>();
        List<String> firstName = new ArrayList<>();
        List<List<Double>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            List<String> rowData = getdata.get(i);
            ArrayList<String> newList = new ArrayList<>();
            double snum=0;
            for (int i1 = 0; i1 < rowData.size(); i1++) {
                String s = rowData.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    newList.add(s);
                    if (i != 0) {
                        if (i1 !=0) {
                            snum += Double.parseDouble(s);
                        }
                    }
                }
            }

            List<Double> doubles = new ArrayList<>();
            if (!CollectionUtils.isEmpty(newList)) {
                if (i == 0) {
                    firstName.addAll(newList);
                } else {
                    for (int i1 = 0; i1 < newList.size(); i1++) {
                        String s = newList.get(i1);
                        if (i1==0) {
                            xlist.add(s);
                        }else {
                            double v = Double.parseDouble(s);
                            doubles.add(v/snum);
                        }
                    }
                }
                if (!CollectionUtils.isEmpty(doubles)) {
                    dataList.add(doubles);
                }

            }
        }

        firstName.remove(0);
        List<List<Double>> datass = new ArrayList<>();
        for (int i = 0; i < firstName.size(); i++) {
            List<Double> datas = new ArrayList<>();
            datass.add(datas);
        }


        for (int i = 0; i < dataList.size(); i++) {
            List<Double> doubles = dataList.get(i);
            for (int i1 = 0; i1 < doubles.size(); i1++) {
                List<Double> doubles1 = datass.get(i1);
                doubles1.add(doubles.get(i1));
            }
        }



        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        JSONObject xAxis = (JSONObject) jsonObject.get("xAxis");
//        xlist.remove(0);
        xAxis.put("data",xlist);
        jsonObject.put("xAxis",xAxis);

        JSONObject legend = (JSONObject) jsonObject.get("legend");

        List<JSONObject> newList =new ArrayList<>();
        List<Map> maps =new ArrayList<>();
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(0);
        for (int i = 0; i < firstName.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);

            jsonObject2.put("name",firstName.get(i));
            Map<String, String> map = new HashMap<>();
            map.put("name",firstName.get(i));
            maps.add(map);
            jsonObject2.put("data",datass.get(i));
            newList.add(jsonObject2);
        }
        legend.put("data",maps);
        jsonObject.put("legend",legend);

        jsonObject.put("series",newList);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV262(List<List<String>> getdata, Long configId) {

        List<String> xlist = new ArrayList<>();
        List<String> xdata = getdata.get(0);
        for (int i = 1; i < xdata.size(); i++) {
            String s = xdata.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                xlist.add(s);
            }
        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());


        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject json = series.get(0);

        List<Map> maps = new ArrayList<>();
        List<JSONObject> jsonObjects = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> list = getdata.get(i);
            if (!CollectionUtils.isEmpty(list)) {
                ArrayList<String> newList = new ArrayList<>();
                for (int i1 = 0; i1 < list.size(); i1++) {
                    String s = list.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        newList.add(s);
                    }
                }
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.putAll(json);
                jsonObject1.put("name", newList.get(0));
                Map<String, String> map = new HashMap<>();
                map.put("name", newList.get(0));
                maps.add(map);
                newList.remove(0);
                jsonObject1.put("data", newList);
                jsonObjects.add(jsonObject1);
            }
        }

        JSONObject xAxis = (JSONObject) jsonObject.get("xAxis");
        xAxis.put("data", xlist);
        jsonObject.put("xAxis", xAxis);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        legend.put("data", maps);
        jsonObject.put("legend", legend);

        jsonObject.put("series", jsonObjects);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV261(List<List<String>> getdata, Long configId) {
        List<List<Object>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            if (i == 0) {
                List<Object> lists = new ArrayList<>();
                lists.addAll(getdata.get(i));
                dataList.add(lists);
            } else {
                List<String> rowData = getdata.get(i);
                if (!ObjectUtils.isEmpty(rowData)) {
                    List<Object> singleData = new ArrayList<>();
                    for (int i1 = 0; i1 < rowData.size(); i1++) {
                        if (i1 == 0) {
                            String s = rowData.get(i1);
                            if (!ObjectUtils.isEmpty(s)) {
                                singleData.add(rowData.get(i1));
                            } else {
                                singleData.add(0);
                            }
                        } else {
                            String s = rowData.get(i1);
                            if (!ObjectUtils.isEmpty(s)) {
                                singleData.add(Double.parseDouble(rowData.get(i1)));
                            } else {
                                singleData.add(0);
                            }
                        }
                    }
                    dataList.add(singleData);
                }
            }

        }

        ChartXDataVo xData = new ChartXDataVo();
        xData.setSource(dataList);


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", xData);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject o = series.get(1);
        List<JSONObject> seriesList = new ArrayList<>();
        for (int i = 1; i < getdata.get(0).size(); i++) {
            JSONObject o1 = new JSONObject();
            o1.putAll(o);
            o1.put("name", getdata.get(0).get(i));
            seriesList.add(o1);
        }
        jsonObject.put("series", seriesList);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<String> fistName = getdata.get(0);
        fistName.remove(0);
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 0; i < fistName.size(); i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(fistName.get(i));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV29(List<List<String>> getdata, Long configId) {
        List<String> xdata = new ArrayList<>();
        List<String> xList = getdata.get(0);
        if (!CollectionUtils.isEmpty(xList)) {
            for (int i = 0; i < xList.size(); i++) {
                String s = xList.get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    xdata.add(s);
                }
            }
        }

        List<JSONObject> datas = new ArrayList<>();

        for (int i = 1; i < getdata.size(); i++) {
            List<List<Object>> groupList = new ArrayList<>();
            String groupName = new String();
            List<String> colData = getdata.get(i);
            for (int i1 = 0; i1 < colData.size(); i1++) {
                String s = colData.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    if (i1 == 0) {
                        groupName = s;
                    } else {
                        List<Object> cellData = new ArrayList<>();
                        cellData.add(Double.parseDouble(s));
                        groupList.add(cellData);
                    }
                }
            }

            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("value", groupList);
            jsonObject2.put("name", groupName);
            jsonObject2.put("areaStyle", new ArrayList<>());
            datas.add(jsonObject2);
        }


        List<ChartLegendData> radarList = new ArrayList<>();
        for (int i = 1; i < xdata.size(); i++) {
            ChartLegendData chartLegendData = new ChartLegendData();
            chartLegendData.setName(xdata.get(i));
            radarList.add(chartLegendData);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        List<JSONObject> radar = (List<JSONObject>) jsonObject.get("radar");
        for (int i = 0; i < radar.size(); i++) {
            JSONObject jsonObject1 = radar.get(i);
            jsonObject1.put("indicator", radarList);

            JSONObject jsonObject2 = series.get(i);
            jsonObject2.put("data", datas);
        }
        jsonObject.put("radar", radar);

        jsonObject.put("series", series);

        ArrayList<Map> maps = new ArrayList<>();
        JSONObject legend = (JSONObject) jsonObject.get("legend");
        for (int i = 0; i < datas.size(); i++) {
            JSONObject jsonObject1 = datas.get(i);
            String name = (String) jsonObject1.get("name");
            HashMap<String, String> map = new HashMap<>();
            map.put("name", name);
            maps.add(map);
        }
        legend.put("data", maps);
        jsonObject.put("legend", legend);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV28(List<List<String>> getdata, Long configId) {
        List<String> xdata = getdata.get(0);

        ArrayList<ChartXDataVo> chartXDataVos = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<List<Object>> groupList = new ArrayList<>();
            ChartXDataVo sData = new ChartXDataVo();
            List<String> colData = getdata.get(i);
            for (int i1 = 1; i1 < colData.size(); i1++) {
                List<Object> cellData = new ArrayList<>();
                cellData.add(xdata.get(i1));
                cellData.add(Double.parseDouble(colData.get(i1)));
                groupList.add(cellData);
            }
            sData.setSource(groupList);
            chartXDataVos.add(sData);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", chartXDataVos);

        int size = getdata.size();
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject o = series.get(1);
        List<JSONObject> seriesList = new ArrayList<>();
        for (int i = 1; i < size; i++) {
            JSONObject o1 = new JSONObject();
            o1.putAll(o);
            o1.put("name", getdata.get(i).get(0));
            o1.put("datasetIndex", i - 1);
            seriesList.add(o1);
        }
        jsonObject.put("series", seriesList);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 1; i < size; i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(getdata.get(i).get(0));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV26(List<List<String>> getdata, Long configId) {
        List<Map> roomName = new ArrayList<>();

        for (int i = 1; i < getdata.size(); i++) {
            List<String> strings = getdata.get(i);
            HashMap<String, String> map = new HashMap<>();
            String name = strings.get(0);
            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(name) || !name.equals("")) {
                map.put("name", strings.get(0));
            }
            roomName.add(map);
        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        legend.put("data", roomName);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject json = series.get(0);
        ArrayList<JSONObject> list = new ArrayList<>();

        for (int i = 0; i < roomName.size(); i++) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.putAll(json);
            jsonObject1.put("name", roomName.get(i).get("name"));
            List<String> list1 = getdata.get(i + 1);
            ArrayList<String> newList = new ArrayList<>();
            for (int i1 = 0; i1 < list1.size(); i1++) {
                String s = list1.get(i1);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                    newList.add(s);
                }
            }
            if (newList.size() >= 2) {
                List<String> sublistExcludingFirstTwo = newList.subList(1, list1.size());
                jsonObject1.put("data", sublistExcludingFirstTwo);
            }
            list.add(jsonObject1);
        }

        jsonObject.put("legend", legend);
        jsonObject.put("series", list);

        ArrayList<String> strings = new ArrayList<>();
        List<String> list1 = getdata.get(0);
        for (int i = 1; i < list1.size(); i++) {
            String s = list1.get(i);
            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                strings.add(s);
            }
        }
        JSONObject yAxis = (JSONObject) jsonObject.get("yAxis");
        yAxis.put("data", strings);
        jsonObject.put("yAxis", yAxis);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV52(List<List<String>> getdata, Long configId) {
        List<String> groupName = new ArrayList<>();


        List<List<Double>> groupList = new ArrayList<>();

        List<Map> maps = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> colData = getdata.get(i);
            if (!CollectionUtils.isEmpty(colData)) {
                List<String> data = new ArrayList<>();
                for (int i1 = 0; i1 < colData.size(); i1++) {
                    String s = colData.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        data.add(s);
                    }
                }

                if (data.size() == 1) {
                    if (i != 1) {
                        Map map = new HashMap<>();
                        map.put("source", groupList);
                        maps.add(map);
                        groupList = new ArrayList<>();
                    }
                    groupName.addAll(data);
                } else {
                    List<Double> dataList = new ArrayList<>();
                    dataList.add(Double.parseDouble(data.get(0)));
                    dataList.add(Double.parseDouble(data.get(1)));
                    groupList.add(dataList);
                    if (getdata.size() - 1 == i) {
                        Map map = new HashMap<>();
                        map.put("source", groupList);
                        maps.add(map);
                    }
                }
            }
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", maps);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(0);

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        for (int i = 0; i < groupName.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);
            jsonObject2.put("datasetIndex", i);
            jsonObject2.put("name", groupName.get(i));
            jsonObjects.add(jsonObject2);
        }
        jsonObject.put("series", jsonObjects);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV53(List<List<String>> getdata, Long configId) {
        List<String> groupName = new ArrayList<>();

        List<List<List<String>>> newList = new ArrayList<>();

        List<List<String>> list = new ArrayList<>();


        for (int i = 1; i < getdata.size(); i++) {
            List<String> sdata = getdata.get(i);
            if (!CollectionUtils.isEmpty(sdata)) {
                List<String> data = new ArrayList<>();
                for (int i1 = 0; i1 < sdata.size(); i1++) {
                    String s = sdata.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        data.add(s);
                    }
                }

                if (!CollectionUtils.isEmpty(data)) {
                    if (i == getdata.size() - 1) {
                        list.add(data);
                        newList.add(list);
                    } else if (i == 1) {
                        groupName.add(data.get(0));
                    } else {
                        if (getdata.get(i).size() == 1) {
                            groupName.add(data.get(0));
                            newList.add(list);
                            list = new ArrayList<>();
                        } else {
                            list.add(data);
                        }
                    }
                }
            }
        }

        List<Map> maps = new ArrayList<>();

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject json = series.get(0);

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();


        for (int i = 0; i < newList.size(); i++) {
            List<List<String>> lists = newList.get(i);
            HashMap<String, Object> map = new HashMap<>();
            map.put("source", lists);
            maps.add(map);

            double[] x = new double[lists.size()];
            double[] y = new double[lists.size()];

            for (int i1 = 0; i1 < lists.size(); i1++) {
                List<String> sources = lists.get(i1);
                for (int i2 = 0; i2 < sources.size(); i2++) {
                    x[i1] = Double.parseDouble(sources.get(0));
                    y[i1] = Double.parseDouble(sources.get(1));
                }
            }
            Map service = ExcelDataUtils.getService1(x, y);
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.putAll(json);
            jsonObject1.put("datasetIndex", i);
            jsonObject1.put("name", groupName.get(i));
            JSONObject markLine1 = (JSONObject) jsonObject1.get("markLine");
            JSONObject markLine = new JSONObject();
            markLine.putAll(markLine1);
            JSONObject label1 = (JSONObject) markLine.get("label");
            JSONObject label = new JSONObject();
            label.putAll(label1);
            label.put("formatter", service.get("formatter"));
            markLine.put("label", label);

            JSONObject tooltip1 = (JSONObject) markLine.get("tooltip");
            JSONObject tooltip = new JSONObject();
            tooltip.putAll(tooltip1);
            tooltip.put("formatter", service.get("formatter"));
            markLine.put("tooltip", tooltip);

            List<JSONObject> data = (List<JSONObject>) markLine.get("data");
            List<JSONObject> data1 = (List<JSONObject>) data.get(0);
            List<JSONObject> jsonObjects1 = new ArrayList<>();
            List<List<JSONObject>> jsonObjects2 = new ArrayList<>();
            for (int i1 = 0; i1 < data1.size(); i1++) {
                JSONObject jsonObject2 = data1.get(i1);
                JSONObject jsonObject3 = new JSONObject();
                jsonObject3.putAll(jsonObject2);
                if (i1 == 0) {
                    jsonObject3.put("coord", service.get("min"));
                } else {
                    jsonObject3.put("coord", service.get("max"));
                }
                jsonObjects1.add(jsonObject3);
            }
            jsonObjects2.add(jsonObjects1);
            markLine.put("data", jsonObjects2);
            jsonObject1.put("markLine", markLine);
            jsonObjects.add(jsonObject1);
        }

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        ArrayList<Map> maps1 = new ArrayList<>();
        for (int i = 0; i < groupName.size(); i++) {
            Map map = new HashMap<>();
            map.put("name", groupName.get(i));
            maps1.add(map);
        }

        legend.put("data", maps1);
        jsonObject.put("legend", legend);


        jsonObject.put("series", jsonObjects);
        jsonObject.put("dataset", maps);


        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV51(List<List<String>> getdata, Long configId) {
        List<String> groupName = new ArrayList<>();

        List<List<List<Object>>> newList = new ArrayList<>();

        List<List<Object>> list = new ArrayList<>();


        for (int i = 1; i < getdata.size(); i++) {
            List<String> sdata = getdata.get(i);
            if (!CollectionUtils.isEmpty(sdata)) {
                List<String> data = new ArrayList<>();
                for (int i1 = 0; i1 < sdata.size(); i1++) {
                    String s = sdata.get(i1);

                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        data.add(s);
                    }
                }

                if (!CollectionUtils.isEmpty(data)) {
                    if (i == getdata.size() - 1) {
                        List<Object> datas = new ArrayList<>();
                        for (int i1 = 0; i1 < data.size(); i1++) {
                            String s = data.get(i1);
                            datas.add(Double.parseDouble(s));
                        }
                        list.add(datas);
                        newList.add(list);
                    } else if (i == 1) {
                        groupName.add(data.get(0));
                    } else {
                        if (getdata.get(i).size() == 1) {
                            groupName.add(data.get(0));
                            newList.add(list);
                            list = new ArrayList<>();
                        } else {
                            List<Object> datas = new ArrayList<>();
                            for (int i1 = 0; i1 < data.size(); i1++) {
                                String s = data.get(i1);
                                datas.add(Double.parseDouble(s));
                            }
                            list.add(datas);
                        }
                    }
                }
            }
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        ArrayList<Map> mapss = new ArrayList<>();
        for (int i = 0; i < newList.size(); i++) {
            Map map = new HashMap<>();
            map.put("source", newList.get(i));
            mapss.add(map);
        }

        jsonObject.put("dataset", mapss);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(1);
        ArrayList<Map> maps = new ArrayList<>();

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        for (int i = 0; i < groupName.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);
            jsonObject2.put("datasetIndex", i);
            jsonObject2.put("name", groupName.get(i));
            Map<String, String> map = new HashMap<>();
            map.put("name", groupName.get(i));
            maps.add(map);
            jsonObjects.add(jsonObject2);
        }
        jsonObject.put("series", jsonObjects);

        legend.put("data", maps);
        jsonObject.put("legend", legend);


        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }
    /*
        private ChartSmartVo getChartV24(List<List<String>> getdata, Long configId) {
            List<String> fistName = new ArrayList<>();
            List<String> data = getdata.get(0);
            for (int i = 0; i < data.size(); i++) {
                String s = data.get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    fistName.add(s);
                }
            }

            List<List<String>> newList = new ArrayList<>();
            for (int i = 1; i < getdata.size(); i++) {
                List<String> list = getdata.get(i);
                if (!CollectionUtils.isEmpty(list)) {
                    List<String> list1 = new ArrayList<>();
                    for (int i1 = 0; i1 < list.size(); i1++) {
                        String s = list.get(i1);
                        if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                            list1.add(s);
                        }
                    }
                    newList.add(list1);
                }
            }

            Map<String, List<List<String>>> map = new HashMap<>();
            newList.add(0, fistName);
            map.put("source", newList);
            ArrayList<Map> maps = new ArrayList<>();
            maps.add(map);

            ChartConfigs configs = chartConfigsService.getById(configId);
            JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

            jsonObject.put("dataset", maps);

            List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
            JSONObject json = series.get(0);

            List<JSONObject> jsonObjects = new ArrayList<>();
            ArrayList<Map> namesMap = new ArrayList<>();
            for (int i = 1; i < fistName.size(); i++) {
                String s = fistName.get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    JSONObject jsonObject1 = new JSONObject();
                    jsonObject1.putAll(json);

                    jsonObject1.put("name", s);
                    HashMap<String, String> nameMap = new HashMap<>();
                    nameMap.put("name", s);
                    namesMap.add(nameMap);
                    jsonObjects.add(jsonObject1);
                }
            }
            jsonObject.put("series", jsonObjects);

            JSONObject legend = (JSONObject) jsonObject.get("legend");
            legend.put("data", namesMap);
            jsonObject.put("legend", legend);

            ChartSmartVo chartSmartVo = new ChartSmartVo();
            chartSmartVo.setConfigId(configs.getId());
            chartSmartVo.setConfigName(configs.getConfigName());
            chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
            chartSmartVo.setChartTypeId(configs.getChartTypeId());
            return chartSmartVo;
        }*/
    private ChartSmartVo getChartV24(List<List<String>> getdata, Long configId) {
        List<String> fistName = new ArrayList<>();
        List<String> data = getdata.get(0);
        for (int i = 0; i < data.size(); i++) {
            String s = data.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                fistName.add(s);
            }
        }

        List<List<String>> newList = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> list = getdata.get(i);
            if (!CollectionUtils.isEmpty(list)) {
                List<String> list1 = new ArrayList<>();
                for (int i1 = 0; i1 < list.size(); i1++) {
                    String s = list.get(i1);
                    if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                        list1.add(s);
                    }
                }
                newList.add(list1);
            }
        }

        Map<String, List<List<String>>> map = new HashMap<>();
        newList.add(0,fistName);
        map.put("source",newList);
        ArrayList<Map> maps = new ArrayList<>();
        maps.add(map);

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());

        jsonObject.put("dataset",maps);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject json = series.get(0);

        List<JSONObject> jsonObjects = new ArrayList<>();
        ArrayList<Map> namesMap = new ArrayList<>();
        for (int i = 1; i < fistName.size(); i++) {
            String s = fistName.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.putAll(json);

                jsonObject1.put("name",s);
                HashMap<String, String> nameMap = new HashMap<>();
                nameMap.put("name",s);
                namesMap.add(nameMap);
                jsonObjects.add(jsonObject1);
            }
        }
        jsonObject.put("series",jsonObjects);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        legend.put("data",namesMap);
        jsonObject.put("legend",legend);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }
    private ChartSmartVo getChartV23(List<List<String>> getdata, Long configId) {
        List<String> xdata = new ArrayList<>();
        List<String> xlist = getdata.get(0);
        for (int i = 1; i < xlist.size(); i++) {
            String s = xlist.get(i);
            if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                xdata.add(s);
            }
        }
//        xdata.remove(0);

        List<ChartXDataVo> chartXDataVos = new ArrayList<>();
        List<String> ydata = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<List<Object>> groupList = new ArrayList<>();
            ChartXDataVo sData = new ChartXDataVo();
            List<String> list = getdata.get(i);
            for (int i1 = 0; i1 < list.size(); i1++) {
                String s = list.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    if (i1 == 0) {
                        ydata.add(s);
                    } else {
                        List<Object> cellData = new ArrayList<>();
                        cellData.add(xdata.get(i1 - 1));
                        cellData.add(Double.parseDouble(s));
                        groupList.add(cellData);
                    }
                }
            }
            sData.setSource(groupList);
            chartXDataVos.add(sData);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", chartXDataVos);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject jsonObject1 = series.get(1);

        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        for (int i = 0; i < ydata.size(); i++) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.putAll(jsonObject1);
            jsonObject2.put("datasetIndex", i);
            jsonObject2.put("name", ydata.get(i));
            jsonObjects.add(jsonObject2);
        }
        jsonObject.put("series", jsonObjects);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
//            xdata.remove(0);
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 0; i < ydata.size(); i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(ydata.get(i));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV22(List<List<String>> getdata, Long configId) {
        List<List<Object>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            List<String> rowData = getdata.get(i);
            ArrayList<String> newList = new ArrayList<>();
            for (int i1 = 0; i1 < rowData.size(); i1++) {
                String s = rowData.get(i1);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    newList.add(s);
                }
            }
            if (!CollectionUtils.isEmpty(newList)) {
                if (i == 0) {
                    List<Object> lists = new ArrayList<>();
                    lists.addAll(newList);
                    dataList.add(lists);
                } else {
                    List<Object> singleData = new ArrayList<>();
                    for (int i1 = 0; i1 < newList.size(); i1++) {
                        if (i1 == 0) {
                            String s = newList.get(i1);
                            if (!ObjectUtils.isEmpty(s)) {
                                singleData.add(newList.get(i1));
                            } else {
                                singleData.add(0);
                            }
                        } else {
                            singleData.add(Double.parseDouble(newList.get(i1)));
                        }
                    }
                    dataList.add(singleData);
                }
            }
        }

        ChartXDataVo xData = new ChartXDataVo();
        xData.setSource(dataList);


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", xData);

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject o = series.get(1);
        List<JSONObject> seriesList = new ArrayList<>();
        for (int i = 1; i < getdata.get(0).size(); i++) {
            JSONObject o1 = new JSONObject();
            o1.putAll(o);
            o1.put("name", getdata.get(0).get(i));
            seriesList.add(o1);
        }
        jsonObject.put("series", seriesList);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<String> fistName = getdata.get(0);
        fistName.remove(0);
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 0; i < fistName.size(); i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(fistName.get(i));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    private ChartSmartVo getChartV21(List<List<String>> getdata, Long configId) {
        List<String> xList = new ArrayList<>();
        List<String> yList = new ArrayList<>();


        List<List<String>> dataList = new ArrayList<>();
        for (int i = 0; i < getdata.size(); i++) {
            List<String> ss = getdata.get(i);
            if (!CollectionUtils.isEmpty(ss) && !ss.equals("")) {
                if (i == 0) {
                    for (int i1 = 1; i1 < ss.size(); i1++) {
                        String y = ss.get(i1);
                        if (!ObjectUtils.isEmpty(y) && !y.equals("")) {
                            yList.add(y);
                        }
                    }
                } else {
                    String x = ss.get(0);
                    if (!ObjectUtils.isEmpty(x) && !x.equals("")) {
                        xList.add(x);
                    }
                    getdata.get(i).remove(0);
                    dataList.add(getdata.get(i));
                }
            }
        }


//        yList.remove(0);

        List<ChartXDataVo> xData = new ArrayList<>();

        for (int i = 0; i < yList.size(); i++) {

            String y = yList.get(i);
            List<List<Object>> newDataList = new ArrayList<>();
            for (int j = 0; j < xList.size(); j++) {
                String s = dataList.get(j).get(i);
                if (!ObjectUtils.isEmpty(s) && !s.equals("")) {
                    String x = xList.get(j);
                    List<Object> cellList = new ArrayList<>();
                    cellList.add(x);
                    cellList.add(y);
                    cellList.add(Double.parseDouble(s));
                    newDataList.add(cellList);
                }
            }
            ChartXDataVo chartXDataVo = new ChartXDataVo();
            chartXDataVo.setSource(newDataList);
            xData.add(chartXDataVo);
        }


        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        jsonObject.put("dataset", xData);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<ChartLegendData> chartLegendData = new ArrayList<>();

        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject o = series.get(1);
        List<JSONObject> seriesList = new ArrayList<>();
        for (int i = 0; i < yList.size(); i++) {
            JSONObject o1 = new JSONObject();
            o1.putAll(o);
            o1.put("datasetIndex", i);
            o1.put("name", yList.get(i));
            seriesList.add(o1);

            ChartLegendData data = new ChartLegendData();
            data.setName(yList.get(i));
            chartLegendData.add(data);
        }
        jsonObject.put("series", seriesList);

        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);

        JSONObject grid3D = (JSONObject) jsonObject.get("grid3D");
//            ChartXDataVo chartXDataVo = xData.get(0);
//            int size = chartXDataVo.getSource().size();
//            int i = size * 8;

        if (xList.size() > 10 || yList.size() > 10) {
            grid3D.put("boxWidth", xList.size() * 8);
            grid3D.put("boxDepth", yList.size() * 8);

        } else if (xList.size() <= 10 && yList.size() <= 10) {
            grid3D.put("boxWidth", xList.size() * 20);
            grid3D.put("boxDepth", yList.size() * 20);
        }

//            JSONObject grid3D = (JSONObject) jsonObject.get("grid3D");
//            ChartXDataVo chartXDataVo = xData.get(0);
//            int size = chartXDataVo.getSource().size();
//            int i = size * 8;
//
//            grid3D.put("boxWidth", i);
//
        jsonObject.put("grid3D", grid3D);

        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }


    private ChartSmartVo getChartV1(List<List<String>> getdata, Long configId) {

        List<String> fistName = new ArrayList<>();
        List<String> nameList = getdata.get(0);
        for (int i = 0; i < nameList.size(); i++) {
            String s = nameList.get(i);
            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                fistName.add(s);
            }
        }

        List<String> roomName = new ArrayList<>();


        List<List<String>> list = new ArrayList<>();
        list.add(fistName);

        List<Map> maps = new ArrayList<>();
        for (int i = 1; i < getdata.size(); i++) {
            List<String> list1 = getdata.get(i);
            if (!CollectionUtils.isEmpty(list1)) {
                List<String> data = new ArrayList<>();
                for (int i1 = 0; i1 < list1.size(); i1++) {
                    String s = list1.get(i1);
                    if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(s) && !s.equals("")) {
                        data.add(s);
                    }
                }

                if (data.size() == 1) {
                    if (i != 1) {
                        Map map = new HashMap<>();
                        map.put("source", list);
                        maps.add(map);
                        list = new ArrayList<>();
                        list.add(fistName);
                    }
                    roomName.add(data.get(0));
                } else {
                    list.add(data);
                    if (i == getdata.size() - 1) {
                        Map map = new HashMap<>();
                        map.put("source", list);
                        maps.add(map);
                    }
                }
            }

        }

        ChartConfigs configs = chartConfigsService.getById(configId);
        JSONObject jsonObject = JSON.parseObject(configs.getConfigValue());
        List<JSONObject> series = (List<JSONObject>) jsonObject.get("series");
        JSONObject series1 = series.get(0);
        List<JSONObject> sDatas = new ArrayList<>();


//            fistName.remove(0);
        if (roomName.size() < 1) {
            for (int i = 1; i < fistName.size(); i++) {
                JSONObject object = new JSONObject();
                object.putAll(series1);
                object.put("name", fistName.get(i));
                sDatas.add(object);
            }
        } else {
            for (int i = 0; i < roomName.size(); i++) {
//                Integer indexNum = roomNameIndex.get(i);
                for (Integer integer = 1; integer < fistName.size(); integer++) {
                    JSONObject object = new JSONObject();
                    object.putAll(series1);
                    object.put("stack", roomName.get(i));
                    object.put("datasetIndex", i);
                    object.put("name", fistName.get(integer));
                    sDatas.add(object);
                }
            }
        }


        jsonObject.put("dataset", maps);
        jsonObject.put("series", sDatas);

        JSONObject legend = (JSONObject) jsonObject.get("legend");
        List<ChartLegendData> chartLegendData = new ArrayList<>();
        for (int i = 1; i < fistName.size(); i++) {
            ChartLegendData data = new ChartLegendData();
            data.setName(fistName.get(i));
            chartLegendData.add(data);
        }
        legend.put("data", chartLegendData);
        jsonObject.put("legend", legend);
        ChartSmartVo chartSmartVo = new ChartSmartVo();
        chartSmartVo.setConfigId(configs.getId());
        chartSmartVo.setConfigName(configs.getConfigName());
        chartSmartVo.setConfigValue(JSON.toJSONString(jsonObject));
        chartSmartVo.setChartTypeId(configs.getChartTypeId());
        return chartSmartVo;
    }

    //前8行是空白
    public static Sheet convertDataListToSheets(List<Map<String, Object>> dataList) {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();

        // Insert 8 blank rows before starting the data
        for (int i = 0; i < 8; i++) {
            sheet.createRow(i);
        }

        // Populate sheet with data starting from the ninth row
        int rowIndex = 8; // Start from the ninth row
        for (Map<String, Object> data : dataList) {
            Row row = sheet.createRow(rowIndex++);
            int cellIndex = 0;
            for (Map.Entry<String, Object> entry : data.entrySet()) {
                Cell cell = row.createCell(cellIndex++);
                setCellValue(cell, entry.getValue());
            }
        }

        return sheet;
    }

    // 读取 Excel 数据并返回 List<List<String>> 格式，从指定行开始读取
/*    private List<List<String>> readExcelData(Sheet sheet, int startRow) {
        List<List<String>> data = new ArrayList<>();
        try {
            // 遍历行
            for (int i = startRow; i <= sheet.getLastRowNum(); i++) {
                Row row = sheet.getRow(i);
                if (row == null) {
                    continue; // 如果行为空，跳过
                }

                List<String> rowData = new ArrayList<>();
                // 遍历单元格
                for (Cell cell : row) {
                    // 读取单元格内容并添加到行数据列表中
                    CellType cellType = cell.getCellType();
                    if (cellType == CellType.STRING) {
                        rowData.add(cell.getStringCellValue());
                    } else if (cellType == CellType.NUMERIC) {
                        rowData.add(String.valueOf(cell.getNumericCellValue()));
                    } else {
                        rowData.add(""); // 其他类型的单元格暂时空字符串处理
                    }
                }
                // 将一行数据添加到整体数据列表中
                data.add(rowData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }*/


    public static Sheet convertDataListToSheetRemoveNineAndOne(List<Map<String, Object>> dataList) {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();

        // Insert 8 blank rows before starting the data
        for (int i = 0; i < 8; i++) {
            sheet.createRow(i);
        }

        // Populate sheet with data starting from the ninth row
        int rowIndex = 8; // Start from the ninth row
        for (Map<String, Object> data : dataList) {
            Row row = sheet.createRow(rowIndex++);
            int cellIndex = 0;
            for (Map.Entry<String, Object> entry : data.entrySet()) {
                Cell cell = row.createCell(cellIndex++);
                setCellValue(cell, entry.getValue());
            }
        }

        // Remove the first cell of the ninth row (index 8)
        if (sheet.getRow(8) != null && sheet.getRow(8).getCell(0) != null) {
            sheet.getRow(8).removeCell(sheet.getRow(8).getCell(0));
        }

        return sheet;
    }

    private static void setCellValue(Cell cell, Object value) {
        if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Number) {
            cell.setCellValue(((Number) value).doubleValue());
        } else if (value instanceof Boolean) {
            cell.setCellValue((Boolean) value);
        } else if (value instanceof Date) {
            cell.setCellValue((Date) value);
        } else {
            cell.setCellValue(value != null ? value.toString() : "");
        }
    }

}
